#include "gpio.h"
#include "../system/system.h"

#define EX_INT1_InterruptFlagClear()       (IFS1bits.INT1IF = 0)
#define EX_INT1_InterruptDisable()     (IEC1bits.INT1IE = 0)
#define EX_INT1_InterruptEnable()       (IEC1bits.INT1IE = 1)
#define EX_INT1_NegativeEdgeSet()          (INTCON2bits.INT1EP = 1)
#define EX_INT1_PositiveEdgeSet()          (INTCON2bits.INT1EP = 0)

void GPIO_Initial_g(void)
{

    //    INT1I: External Interrupt 1
    //    Priority: 1
    IPC5bits.INT1IP = 1;
    IFS1bits.INT1IF = 0; //clear interrupt flag
    IEC1bits.INT1IE = 1; //interrupt enable
}

void GPIO_LED_D3_Toggle_g(void)
{
    GPIO_LED_D3 ^= 1;
}

void GPIO_LED_D4_Toggle_g(void)
{
    GPIO_LED_D4 ^= 1;
}

void GPIO_LED_D3_Enable_g(void)
{
    GPIO_LED_D3 = 1;
}

void GPIO_LED_D3_Disable_g(void)
{
    GPIO_LED_D3 = 0;
}

void GPIO_LED_D4_Enable_g(void)
{
    GPIO_LED_D4 = 1;
}

void GPIO_LED_D4_Disable_g(void)
{
    GPIO_LED_D4 = 0;
}

__attribute__((weak)) void Int1Function(void);

//***User Area End->code: Add External Interrupt handler specific headers

/**
   Section: External Interrupt Handlers
 */
/**
  Interrupt Handler for EX_INT1 - INT1
*/
void __attribute__ ( ( interrupt, no_auto_psv ) ) _INT1Interrupt(void)
{
    //***User Area Begin->code: External Interrupt 1***
    Int1Function();
    //***User Area End->code: External Interrupt 1***
    EX_INT1_InterruptFlagClear();
}